<template>
	<view class="template-create tn-safe-area-inset-bottom">
		<tn-nav-bar fixed :isBack="true">
			实名认证
		</tn-nav-bar>

		<view class="tn-safe-area-inset-bottom" v-if="!body.sfz_name"
			:style="{paddingTop: vuex_custom_bar_height + 'px'}">

			<view class=" tn-flex-2 tn-bg-gray--light tn-margin" style="border-radius: 10rpx;padding: 20rpx 30rpx;">
				<input placeholder="请填写姓名" name="input" v-model="sfz_name" placeholder-style="color:#AAAAAA"></input>
			</view>


			<view class="tn-margin tn-bg-gray--light" style="border-radius: 10rpx;padding: 20rpx 30rpx;">
				<input placeholder="请填写身份证号" name="input" v-model="sfz_number"
					placeholder-style="color:#AAAAAA"></input>
			</view>


			<view class="tn-flex ">
				<view class="tn-flex-1 justify-content-item tn-margin-sm tn-text-center" @click="fabuba()">
					<tn-button :blockRepeatClick="true" backgroundColor="tn-cool-bg-color-6" padding="40rpx 0"
						width="60%" shadow fontBold>
						<text class="tn-icon-success tn-padding-right-xs "></text>
						<text class="">提交认证</text>

					</tn-button>
				</view>
			</view>

		</view>
		<view class="tn-safe-area-inset-bottom" v-else :style="{paddingTop: vuex_custom_bar_height + 'px'}">
		<view class="tn-margin  tn-padding tn-flex  tn-flex-row-center tn-margin-top-sm" style="border-radius: 10rpx;margin-top:150rpx;">
						<view 
							style="font-size: 20px;padding: 80rpx;" >
							<view class="tn-icon-success-circle-fill tn-color-green" style="font-size: 100px;"></view>
							<view style="font-size: 14px;" class="tn-text-center">你的已通过实名认证</view>							
						<view class="tn-color-black tn-text-df tn-text-center tn-padding-top" >
					
						</view>
						
						</view>
		</view>	
		</view>

	</view>
</template>

<script>
	import {
		host
	} from '@/siteinfo.js'
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	export default {
		name: 'TemplateCreate',
		mixins: [template_page_mixin],
		data() {
			return {
				body: [],
				sfz_name: '',
				sfz_number: ''
			}
		},
		onLoad(option) {
			this.info()
		},
		methods: {

			async info() {
				let that = this;
				let result = await that.$request({
					loading: 1,
					method: 'post',
					url: '/chat/user/setindex',
					data: {}
				});


				if (result.statusCode == 200) {
					if (result.data.code == 200) {
						that.body = result.data.data;
					} else {
						uni.showToast({
							icon: 'none',
							title: result.data.msg
						});
					}
				} else {
					uni.showToast({
						icon: 'none',
						title: that.$errorMsg
					});
				}


			},

			async fabuba() {
				let that = this;

				if (this.sfz_name == '') {
					this.msg('姓名不能为空')
					return;
				}
				if (this.sfz_number == '') {
					this.msg('身份证号码不能为空')
					return;
				}


				let arrExp = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; //加权因子  
				let arrValid = [1, 0, "X", 9, 8, 7, 6, 5, 4, 3, 2]; //校验码  
				if (/^\d{17}\d|x$/i.test(this.sfz_number)) {
					let sum = 0,
						idx;
					for (let i = 0; i < this.sfz_number.length - 1; i++) {
						// 对前17位数字与权值乘积求和  
						sum += parseInt(this.sfz_number.substr(i, 1), 10) * arrExp[i];
					}
					// 计算模（固定算法）  
					idx = sum % 11;
					// 检验第18为是否与校验码相等  
					if (arrValid[idx] == this.sfz_number.substr(17, 1).toUpperCase()) {

					} else {
						uni.showToast({
							title: '身份证号码错误！',
							icon: 'none',
							duration: 2000
						});
						return;
					}


				} else {
					uni.showToast({
						title: '身份证号码不正确！',
						icon: 'none',
						duration: 2000
					});
					return;
				}



				let result = await that.$request({
					loading: 1,
					method: 'post',
					url: '/chat/user/set_sfz',
					data: {
						sfz_number: this.sfz_number,
						sfz_name: this.sfz_name
					}
				});


				if (result.statusCode == 200) {
					if (result.data.code == 200) {
						uni.hideLoading()
						this.msg(result.data.msg)
						this.info()
					} else {
						uni.showToast({
							icon: 'none',
							title: result.data.msg
						});
					}
				} else {
					uni.showToast({
						icon: 'none',
						title: that.$errorMsg
					});
				}


			},


		}
	}
</script>

<style lang="scss" scoped>
	.template-edit {}

	/* 胶囊*/
	.tn-custom-nav-bar__back {
		width: 100%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		background-color: rgba(0, 0, 0, 0.15);
		border-radius: 1000rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		color: #FFFFFF;
		font-size: 18px;

		.icon {
			display: block;
			flex: 1;
			margin: auto;
			text-align: center;
		}

		&:before {
			content: " ";
			width: 1rpx;
			height: 110%;
			position: absolute;
			top: 22.5%;
			left: 0;
			right: 0;
			margin: auto;
			transform: scale(0.5);
			transform-origin: 0 0;
			pointer-events: none;
			box-sizing: border-box;
			opacity: 0.7;
			background-color: #FFFFFF;
		}
	}

	/* 底部悬浮按钮 start*/
	.tn-tabbar-height {
		min-height: 100rpx;
		height: calc(120rpx + env(safe-area-inset-bottom) / 2);
	}

	.tn-footerfixed {
		bottom: 0;
		position: fixed;
		width: 100%;
		z-index: 1024;
		box-shadow: 0 1rpx 6rpx rgba(0, 0, 0, 0);

	}

	/* 底部悬浮按钮 end*/

	/* 标签内容 start*/
	.tn-tag-content {
		&__item {
			display: inline-block;
			line-height: 45rpx;
			padding: 10rpx 30rpx;
			margin: 20rpx 20rpx 5rpx 0rpx;

			&--prefix {
				padding-right: 10rpx;
			}
		}
	}

	/* 标签内容 end*/
</style>